package com.aios.action.settings.switches;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.aios.action.AbstractManagementAction;
import com.aios.entity.Switch;
import com.aios.exception.ItemNotFoundException;
import com.aios.exception.NullReferenceAccessException;
import com.aios.service.SwitchService;

public abstract class AbstractSwitchesAction extends AbstractManagementAction {

	private static final long serialVersionUID = 1L;
	protected Switch switches;

	@Qualifier("switchService")
	@Autowired
	protected SwitchService switchService;

	public Switch findById() {
		if (id != null) {
			try {
				return switchService.findById(id);
			} catch (Exception e) {
				addActionError("Switch not found");
				throw new ItemNotFoundException("Id : " + id);
			}
		} else {
			// logger
			throw new NullReferenceAccessException("Id cannot be null");
		}

	}

	public Switch getSwitches() {
		return switches;
	}

	public void setSwitches(Switch switches) {
		this.switches = switches;
	}
}
